$('a').click(function(){parent.checkonline();});
$('.type-select > ul > li').hover(function(){$(this).addClass('on');},function(){$(this).removeClass('on');})

$('.type-select > ul > li').click(function(){
	var val = $(this).attr('data');
	var txt = $(this).text().replace(/(^\s*)|(\s*$)/g, "");
	$(this).parents('ul').siblings().children().eq(0).val(val);
	$(this).parents('ul').siblings().children().eq(1).val(txt);
	$(this).parents('ul').slideToggle(200);
});

$('.type-select').find('input').blur(function(){
	var vals = this.value,cid=0,ctemp=0;
	$(this).parents('div').siblings().children('li').each(function(i){
		var txt = $(this).text().replace(/(^\s*)|(\s*$)/g, "");
		var val = $(this).attr('data');
			ctemp = ctemp<val?val:ctemp;
			if(txt == vals){cid = val;return false;}
	});
	cid!=0?$(this).siblings().val(cid):vals!=''?$(this).siblings().val(parseInt(ctemp)+1):$(this).siblings().val(cid);
});

$('.type-select > ul').hover(
	function(){},
	function(){$(this).slideUp(300);}
);

$('.sel-box-btn').click(function(){
	if(!$('ul').is(':animated'))
	{
		$(this).parent().siblings().slideToggle(300);
	}		
});

$('input[type=file]').change(function(){
	var img = +[1,]?window.URL.createObjectURL(this.files[0]):this.value;
	$('#imgbox').html('<img src="'+img+'" width="520" height="250"/>');
});

if(window.navigator.userAgent.indexOf("Chrome") >= 0)//判断谷歌浏览器
{
	$('#photo').css({'left':-66});
}

var jsond,dataIds = new  Array();
	function closealert()
	{
		$('.s').hide();
	}

	function doupdate()
	{
		$.ajax({
			   type: "POST",
			   url: "",
			   data: 'json='+jsond+'&tp=doupdate',
			   success: function(msg)
			   {
					if(msg != 'null')
					{
						$('.s').hide();
					}					
			   }
			});
	}

var choseTag = true;
	function choseAll()
	{
		if(choseTag)
		{
			$('input[type=checkbox]').attr('checked',true);choseTag = false;
		}else{
			$('input[type=checkbox]').attr('checked',false);choseTag = true;
		}
	}

	function search(p)
	{
		$.ajax({
		   type: "POST",
		   url: "admins_ajax.php",
		   data: $("#searchForm").serialize()+'&page='+p,
		   success: function(json)
		   {
				if(json == 'null')
				{
					alert('没有更多符合条件的数据');
				}else{
					$('#sourceList').html(mkHtml(json));
					$('#ajaxpage > li').eq(p-1).addClass('caheTag').siblings().removeClass('caheTag');
				}
		   }
		});
	}
	
	function del()
	{
		var act = $('input[name=action]').val();
		$.ajax({
		   type: "POST",
		   url: "admins_ajax.php",
		   data: 'action='+act+'&type=del&'+$("input:checked").serialize(),
		   success: function(msg)
		   {
				msg == 'OK'?location.reload():alert(msg);
		   }
		});
	}

	function mkHtml(json)
	{
		var act = $('input[name=action]').val();
		switch(act)
		{
			case 'getvalue':
				var html = "<tr><td>ID</td><td>标题</td><td>链接</td><td width='100'>分类</td><td width='50'>状态</td><td><a href='javascript:;' onclick='choseAll();'>全选</a></td></tr>";
				var data = $.parseJSON(json);
				for(var i=0;i<data.length;i++)
				{
					html += "<tr><td>"+data[i].id+"</td><td>"+data[i].title+"</td><td>"+data[i].link+"</td><td>"+data[i].cates+"</td><td>"+data[i].step+"</td><td><input type='checkbox' name='chose["+data[i].id+"]' value='"+data[i].id+"'/></td></tr>"
				}
				break;
			case 'manage_articles':
				var html = "<tr><td>ID</td><td>标题</td><td>分类</td><td><a href='javascript:;' onclick='choseAll();'>全选</a></td></tr>";
				var data = $.parseJSON(json);
				for(var i=0;i<data.length;i++)
				{
					html += "<tr><td>"+data[i].id+"</td><td><a href='http://cblit.com/page.php?id="+data[i].id+"' target='_blank'>"+data[i].title+"</td><td>"+catename[data[i].cates]+"</td><td><input type='checkbox' name='chose["+data[i].id+"]' value='"+data[i].id+"'/></td></tr>"
				}
				break;
			case 'manage_product':
				var html = "<tr><td>ID</td><td>标题</td><td>分类</td><td><a href='javascript:;' onclick='choseAll();'>全选</a></td></tr>";
				var data = $.parseJSON(json);
				for(var i=0;i<data.length;i++)
				{
					html += "<tr><td>"+data[i].id+"</td><td><a href='http://cblit.com/page.php?id="+data[i].id+"' target='_blank'>"+data[i].title+"</td><td>"+catename[data[i].cates]+"</td><td><input type='checkbox' name='chose["+data[i].id+"]' value='"+data[i].id+"'/></td></tr>"
				}
				break;
			default:
				var html='';
				break;
		}
		return html;
	}

	var dh = $('body').height();
		$('.backcaver').height(dh);
		$('.alertbox').height(dh*0.9);